﻿Imports System.Data
Imports System.Data.OleDb
Imports geraLaudosAutomatico.conexao
Imports System.Text
Public Class municaoDAO
    Private sql As New StringBuilder
    Private objConn As New conexao
    Private i As Integer
    Private municao As New municaoVO

    Public Function getMunicoes() As Generic.List(Of municaoVO)
        sql.Clear()
        sql.Append("SELECT *FROM MUNICAO ORDER BY DESC_TIPO")
        Dim oReader As OleDbDataReader
        Dim lista As New Generic.List(Of municaoVO)
        Try
            Dim oComando As New OleDbCommand(sql.ToString, objConn.abreConexao(True))
            oReader = oComando.ExecuteReader
            While oReader.Read
                municao = New municaoVO
                municao.ID_MUNICAO = IIf(IsDBNull(oReader("ID_MUNICAO")), Nothing, oReader("ID_MUNICAO"))
                municao.CALIBRE = IIf(IsDBNull(oReader("ID_MUNICAO")), Nothing, New calibreVO With {.ID_CALIBRE = oReader("MUNICAO.ID_CALIBRE"), .CALIBRE = oReader("CALIBRE"), .RESTRITO = oReader("RESTRITO"), .CANO_RAIADO = oReader("CANO_RAIADO"), .FUZIL = oReader("FUZIL")})
                municao.DESC_TIPO = IIf(IsDBNull(oReader("DESC_TIPO")), Nothing, oReader("DESC_TIPO"))
                municao.COPM_ESTOJO = IIf(IsDBNull(oReader("COMP_ESTOJO")), Nothing, oReader("COMP_ESTOJO"))
                lista.Add(municao)
            End While
            Return lista
        Catch ex As Exception
            Throw ex
        Finally
            objConn.fechaConexao()
        End Try
    End Function


    Public Function getMunicoes(ByVal id_calibre As Integer) As Generic.List(Of municaoVO)
        sql.Clear()
        sql.Append("SELECT *FROM CALIBRE INNER JOIN MUNICAO ON CALIBRE.ID_CALIBRE = MUNICAO.ID_CALIBRE WHERE MUNICAO.ID_CALIBRE=@ID_CALIBRE ORDER BY DESC_TIPO ")
        Dim oReader As OleDbDataReader
        Dim lista As New Generic.List(Of municaoVO)
        Try
            Dim oComando As New OleDbCommand(sql.ToString, objConn.abreConexao(True))
            oComando.Parameters.AddWithValue("@ID_CALIBRE=", id_calibre)

            oReader = oComando.ExecuteReader
            While oReader.Read
                municao = New municaoVO
                municao.ID_MUNICAO = IIf(IsDBNull(oReader("ID_MUNICAO")), Nothing, oReader("ID_MUNICAO"))
                municao.CALIBRE = IIf(IsDBNull(oReader("ID_MUNICAO")), Nothing, New calibreVO With {.ID_CALIBRE = oReader("MUNICAO.ID_CALIBRE"), .CALIBRE = oReader("CALIBRE"), .RESTRITO = oReader("RESTRITO"), .CANO_RAIADO = oReader("CANO_RAIADO"), .FUZIL = oReader("FUZIL")})
                municao.DESC_TIPO = IIf(IsDBNull(oReader("DESC_TIPO")), Nothing, oReader("DESC_TIPO"))
                municao.COPM_ESTOJO = IIf(IsDBNull(oReader("COMP_ESTOJO")), Nothing, oReader("COMP_ESTOJO"))
                lista.Add(municao)
            End While
            Return lista
        Catch ex As Exception
            Throw ex
        Finally
            objConn.fechaConexao()
        End Try
    End Function
End Class


